package com.xyd.servlet;

import com.xyd.entity.PageBean;
import com.xyd.entity.Product;
import com.xyd.service.ProductSericve;
import com.xyd.service.impl.ProductServiceImpl;
import com.xyd.util.JsonUtil;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 类描述：
 *
 * @author 张吉哲
 * @date 2021/1/11 15:47
 */
@WebServlet("/productAdminShowServlet")
public class ProductAdminShowServlet extends HttpServlet {

  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    String currentPage_str = request.getParameter("currentPage");
    int currentPage = 1;
    if (currentPage_str != null && currentPage_str.length() > 0) {
      currentPage = Integer.parseInt(currentPage_str);
    }

    ProductSericve productSericve = new ProductServiceImpl();
    PageBean<Product> products = productSericve.adminShowProduct(currentPage);

    JsonUtil.toJson(response, products);
  }

  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    doPost(request, response);
  }
}
